package com.itheima.practice.demo01;

public class PartSort {
    public static void main(String[] args) {
        int[] num = {1,2,3,4,5,6,7,8,9,10,11};
        int a = 4;

        long start = System.currentTimeMillis();
        int index = getIndex(num,a);
        System.out.println(index);
        long end = System.currentTimeMillis();
        System.out.println("程序跑了" + (end - start) + "毫秒");
    }

    private static int getIndex(int[] num, int a) {
        int min = 0;
        int max = num.length - 1;

        while (min <= max){
            int mid = (min + max) >> 1;
            if (num[mid] > a){
                max = mid - 1;
            }else if (num[mid] < a){
                min = mid + 1;
            }else {
                return mid;
            }
        }
        return -1;
    }
}
